package com.gaussic.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by Administrator on 2017/3/31 0031.
 */
public class HelloWorldServlet extends HttpServlet {

    /**
     * 查看httpservlet实现的service一看便知，起到了一个controll控制器的作用(转向的)
     * 之后便是跳转至我们熟悉的doget,dopost等方法中
     */
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        System.out.println("doservice..."+this.getInitParameter("encoding"));

        super.service(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        System.out.println("doget...");
        String username = req.getParameter("username");
        //获取请求方式
        String method = req.getMethod();
        //获取输出流
        PrintWriter out = resp.getWriter();
        out.write("Method："+method);
        out.write("<br/>");
        out.write("接收到的参数："+username);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        System.out.println("dopost...");
        doGet(req, resp);
    }
}